home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ 12⁄8⁄89 / 0171-Failure Handling-Dec89 < prev    next >
Encoding:
Text File  |  1989-12-08  |  2.0 KB  |  86 lines  |  [TEXT/GEOL]

  1. Item    9074393                         7-Dec-89        12:17
  2.  
  3. From:   D1950                           CSG, Don Phillips,PRT
  4.  
  5. To:     MACAPP.TECH$                    MacApp Technical
  6.  
  7. Sub:    Failure Handling
  8.  
  9. Geoff and Jeff,
  10.  
  11. Thanks for your explanations. I have another question regarding Failure
  12. Handlers.  This time it's not in an initialization method.
  13.  
  14. What is the best way to implement Failure Handling in the situation below?
  15.  
  16. Is there somewhere in the documentation that I can find this type of
  17. information?
  18.  
  19. Thanks again,
  20. Jo-Anne Droogh
  21.  
  22.  
  23. TTObject4.DoSomethingOtherThanInitialization;
  24.  
  25.     VAR
  26.             tmpObject1  : TTObject1;
  27.             tmpObject2  : TTObject2;
  28.             tmpObject3  : TTObject3;
  29.             fi1         : FailInfo;
  30.             fi2         : FailInfo;
  31.             fi3         : FailInfo;
  32.  
  33.        PROCEDURE LocalFailureHandler1( error : OSErr; message : LONGINT );
  34.  
  35.        BEGIN
  36.         FreeIfObject( tmpObject1 );
  37.     END;
  38.  
  39.        PROCEDURE LocalFailureHandler2( error : OSErr; message : LONGINT );
  40.  
  41.        BEGIN
  42.         FreeIfObject( tmpObject2 );
  43.     END;
  44.  
  45.        PROCEDURE LocalFailureHandler3( error : OSErr; message : LONGINT );
  46.  
  47.        BEGIN
  48.         FreeIfObject( tmpObject3 );
  49.     END;
  50.  
  51. BEGIN
  52.     tmpObject1 := NIL;
  53.     tmpObject2 := NIL;
  54.     tmpObject3 := NIL;
  55.  
  56.     New( tmpObject1 );
  57.     FailNIL( tmpObject1 );
  58.     tmpObject1.IObject1;        { If this fails, it will be freed }
  59.  
  60.     CatchFailures( fi1, LocalFailureHandler1 );
  61.  
  62.    { Do something that could fail. }
  63.  
  64.     New( tmpObject2 );
  65.     FailNIL( tmpObject2 );
  66.     tmpObject2.IObject2;        { If this fails, it will be freed }
  67.  
  68.     CatchFailures( fi2, LocalFailureHandler2 );
  69.  
  70.     { Do something that could fail. }
  71.  
  72.     New( tmpObject3 );
  73.     FailNIL( tmpObject3 );
  74.     tmpObject3.IObject3;        { If this fails, it will be freed }
  75.  
  76.     CatchFailures( fi3, LocalFailureHandler3 );
  77.  
  78.    { Do something that could fail. }
  79.  
  80.     Success( fi3 );         { Order matters here. }
  81.     Success( fi2 );
  82.     Success( fi1 );
  83.  
  84. END;
  85.  
  86.